<?php

use App\Http\Controllers\Admin\AuthController;
use App\Http\Controllers\Admin\Content\ArticleController;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\Finance\SettlementController;
use App\Http\Controllers\Admin\Setting\WebSiteController;
use App\Http\Controllers\Admin\Transaction\OrderController;
use App\Http\Controllers\Admin\UploadController;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    if (auth('admin')->check()) {
        return redirect()->route('admin.welcome');
    }

    return redirect()->route('admin.login'); // 使用命名路由
})->name('index');

// 登录页
Route::get('/login', [AuthController::class, 'index'])->name('login');

Route::post('/authenticate', [AuthController::class, 'authenticate'])->name('authenticate');

Route::middleware('admin.session.auth')->group(function () {
    // 退出登录
    Route::get('/logout', [AuthController::class, 'logout'])->name('logout');

    // 文件上传
    Route::prefix('upload')->name('upload.')->group(function () {
        Route::post('image', [UploadController::class, 'image'])->name('image');
        Route::post('avatar', [UploadController::class, 'avatar'])->name('avatar');
    });

    Route::get('/welcome', [DashboardController::class, 'index'])->name('welcome');
    Route::get('/dashboard', [DashboardController::class, 'dashboard'])->name('dashboard');
    Route::get('/analysis', [DashboardController::class, 'analysis'])->name('analysis');

    // 文章
    Route::apiResource('/articles', ArticleController::class)->names('articles');

    // 订单
    Route::apiResource('/orders', OrderController::class)->names('orders');

    // 结算
    Route::apiResource('/settlements', SettlementController::class)->names('settlements');

    // 系统设置
    Route::prefix('setting')->name('setting.')->group(function () {

        Route::get('/website', [WebSiteController::class, 'index'])->name('website.index');
        Route::post('/website', [WebSiteController::class, 'update'])->name('website.update');

    });
});
